package com.faxsun.admin.web.controller;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.broadleafcommerce.common.extension.ExtensionResultStatusType;
import org.broadleafcommerce.core.order.domain.Order;
import org.broadleafcommerce.openadmin.web.controller.AbstractAdminAbstractControllerExtensionHandler;
import org.broadleafcommerce.openadmin.web.controller.AdminAbstractControllerExtensionManager;
import org.broadleafcommerce.openadmin.web.form.entity.EntityFormAction;

//@Component("fsOrderAdminControllerExtensionHandler")
public class OrderAdminControllerExtensionHandler extends AbstractAdminAbstractControllerExtensionHandler {

	@Resource(name = "blAdminAbstractControllerExtensionManager")
	protected AdminAbstractControllerExtensionManager extensionManager;

	@PostConstruct
	public void init() {
		if (isEnabled()) {
			extensionManager.registerHandler(this);
		}
	}

	@Override
	public ExtensionResultStatusType addAdditionalMainActions(String sectionClassName,
			List<EntityFormAction> actions) {

		if (sectionClassName.equals(Order.class.getName())) {
			// FilterAndSortCriteria sortCriteria = new
			// FilterAndSortCriteria("auditable.dateUpdated");
			// sortCriteria.setSortAscending(false);
			actions.add(new EntityFormAction("OrderFilterAndSort")
					.withButtonClass("unprocessed-order")
					.withUrlPostfix("?internalStatus=PAYMENT_SUCCESS&status=SUBMITTED&sortProperty=submitDate&sortDirection=DESCENDING")
					.withIconClass("icon-gears").withDisplayText("Unprocessed_Order"));

			return ExtensionResultStatusType.HANDLED_CONTINUE;
		}
		return ExtensionResultStatusType.NOT_HANDLED;
	}

}
